@section('title') 菜单 @parent @show
@section('content')
<div class="navbar theme-white">
	<div class="navbar-inner navbar-on-center">
		<div class="left"><a class="link icon-back external" href="{{ $_SERVER['HTTP_REFERER'] }}"> <i class="icon icon-back"></i></a></div>
		<div class="center sliding i18n">购物车</div>
		<div class="right">	<a href="#" class="link btn-clear">清空</a></div>
	</div>
</div>
<div class="pages navbar-through">
	<div class="page no-swipeback page-on-center" data-page="cart-index">
		<div class="page-content">
			<div class="list-block media-list">
				<form id="form" class="list-block" action="{{ route('order.submit') }}">
				<ul class="dish-list">
					<?php foreach($cart as $row) :?>
					<li class="swipeout cart-row" id="li-{{ $row->rowid }}">
						<div class="item-content swipeout-content">
									<div class="item-media">
										<label class="label-checkbox">
											<input type="checkbox" name="product" class="product" value="{{ $row->id }}">
											<div class="item-media"><i class="icon icon-form-checkbox"></i></div>
										</label>
										<?php
										$options = $row->options;
										$url = $options[0] ? Config::get('shihui.upload_url').$options[0] : Config::get('app.url').'/img/no_pic.png';
										?>
										<a href="###" class="external product-img"><img width="80" data-src="<?php echo $url; ?>" class="lazy"></a>
									</div>
									<div class="item-inner product-inner">
										<div class="item-title-row">
											<div class="item-title">{{ $row->name }}</div>
											<div class="item-after product-price">&yen; <span class="subtotal">{{ $row->subtotal }}</span></div>
										</div>
										<div class="item-subtitle btn-qty">
											<div class="buttons-row row">
												价格 {{ $row->price }}
											</div>
										</div>
										<div class="item-subtitle unit-price">
											{{ $row->qty }}张
										</div>
									</div>
						 </div>
						<div class="swipeout-actions-right">
							<a href="#" class="swipeout-delete" id="{{ $row->rowid }}">删除</a>
						</div>
					</li>
					<?php endforeach;?>
				</ul>
                @if(count($cart)>0)
                <div class="list-block words">
                <ul>
                  <li>
                    <div class="item-content">
                      <div class="item-inner">
                        <div class="item-input">
                          <input type="tel" placeholder="联系方式" name="phone" value="@if(Auth::check() && Auth::user()->phone){{ Auth::user()->phone }} @endif">
                        </div>
                      </div>
                    </div>
                  </li>
                  <li class="align-top">
                    <div class="item-content">
                      <div class="item-inner">
                        <div class="item-input">
                          <textarea class="" name="memo" placeholder="其他想说的话"></textarea>
                        </div>
                      </div>
                    </div>
                  </li>
                </ul>
              </div>
              @endif
				</form>
			</div>
			<div class="empty-row" style="@if(count($cart)>0)display:none; @endif">
					<p class="center mt100">您的购物车为空，立即<a class="external" href="{{ route('store.index') }}">选购</a></p>
			</div>
			<div class="content-block">
				
			</div>
		</div>
	</div>
</div>

<div class="toolbar tabbar tabbar-labels">
	<div class="toolbar-inner cart-bottom">
        <div class="left left-price">
            <div class="left check-box">
                <label class="label-checkbox ckall-label">
                    <input type="checkbox" name="ckAll" class="ckall" value="">
                    <div class="item-media"><i class="icon icon-form-checkbox"></i></div>
                </label>
            </div>
            <div class="right total-price-box">
                总价：<span id="total" class="total_product-price due">&yen; <?php echo Cart::total();?></span>
            </div>
        </div>
        <div class="right right-submit">
            <a href="#" class="button order-submit">结算</a>
        </div>
	</div>
</div>
@stop
@section('bodyEnd')
@parent
<script src="{{ Config::get('app.url')}}/js/cart.js"></script>
<script>
$$(document).on('click', '.order-submit', function(){
    if(!ifLogin)
    {  
        location.href= "{{ route('home.login') }}?backurl="+location.href;
        return;
    }
    var productData = myApp.formToJSON('#form');
	var product_ids = productData.product;
    var phone = productData.phone;
    var memo = productData.memo;

	if(product_ids.length<1)
	{
		myApp.alert('请先勾选商品！', '提示');
		return;
	}
	 $$.ajax({
				type: "post",
				dataType: "json",
				url: "{{ route('order.submit') }}",
				data: "&product_ids=" + product_ids+ "&memo=" + memo+"&phone=" + phone,
				success: function(response){
					if(response.type == 1)
					{
						var url = String("{{ route('order.detail', '_field') }}").replace('_field', response.order.id);
						location.href=url;
					} 
					myApp.closeModal();
				}
		});	 


})

$$(document).on('change', '.ckall', function(){
		$$('.product').prop('checked', $$(this).prop('checked'));
		updatePaymentDue();
})

$$(document).on('change', '.product', function(){
		if($$(this).prop('checked') == false)
		{
			$$('.ckall').prop('checked', false);
		}
		updatePaymentDue();
})
$$('.ckall-label').click();

</script>
@stop